--pieces
local base = piece("base")
  body = piece("body") 
    local mainrotor = piece("mainrotor")
    local tailrotor = piece("tailrotor")
    local turret1, sleeve1 = piece("turret1", "sleeve1")
      local barrel1a, firepoint1a = piece("barrel1a", "firepoint1a")  
      local barrel1b, firepoint1b = piece("barrel1b", "firepoint1b")
    local turret2, sleeve2 = piece("turret2", "sleeve2")
      local barrel2, firepoint2 = piece("barrel2", "firepoint2")  
    local turret3 = piece("turret3")
      local firepoint3a, firepoint3b, firepoint3c = piece("firepoint3a", "firepoint3b", "firepoint3c")
    local turret4 = piece("turret4")
      local firepoint4a, firepoint4b, firepoint4c = piece("firepoint4a", "firepoint4b", "firepoint4c")  
  local dustemmiter = piece("dustemmiter")

scriptParams = {
  smokePieces = { body },
  smokeDelay = 300,

  weapons = {
    [1] = {
      turretTurnSpeed = 135,
      sleeveTurnSpeed = 135,
	barrelRecoil = 1,
	--minPitch = -20,
	restores = true,
      --restoreDelay = 3000,  --fast?
	--cegID = 1,
    },
    [2] = {
      turretTurnSpeed = 135,
      sleeveTurnSpeed = 135,
	barrelRecoil = 1,
	--minPitch = -20,
	restores = true,
      --restoreDelay = 3000,  --fast?
	--cegID = 1,
    },
    [3] = {
      turretTurnSpeed = 90,
      sleeveTurnSpeed = 90,
	--minPitch = -20,
	restores = true,
      --restoreDelay = 3000,  --fast?
	--cegID = 1,
    },
    [4] = {
      turretTurnSpeed = 90,
      sleeveTurnSpeed = 90,
	--minPitch = -20,
	restores = true,
      --restoreDelay = 3000,  --fast?
	--cegID = 1,
    },	
  }  
}

include "pre_scripts.lua"

setWeaponPieces(1, turret1, sleeve1, { barrel1a, barrel1b }, { firepoint1a, firepoint1b })
setWeaponPieces(2, turret2, sleeve2, barrel2, firepoint2)
setWeaponPieces(3, turret3, turret3, {}, { firepoint3a, firepoint3b, firepoint3c })
setWeaponPieces(4, turret4, turret4, {}, { firepoint4a, firepoint4b, firepoint4c })

include "scripts.lua"


function script.Killed (recentDamage, maxHealth)
  local severity = recentDamage / maxHealth
  
  if (severity <= 0.25) then
    Explode (body, SFX.NONE)
    Explode (mainrotor, SFX.NONE)
    Explode (tailrotor, SFX.NONE)
    Explode (turret1, SFX.NONE)
     Explode (barrel1a, SFX.NONE)
     Explode (barrel1b, SFX.NONE)
    Explode (turret2, SFX.NONE)
     Explode (barrel2, SFX.NONE)
    Explode (turret3, SFX.NONE)
    Explode (turret4, SFX.NONE)  
	  return 1
  elseif (severity <= 0.50) then
    Explode (body, SFX.NONE)
    Explode (mainrotor, SFX.NONE)
    Explode (tailrotor, SFX.NONE)
    Explode (turret1, SFX.SMOKE + SFX.FIRE)
     Explode (barrel1a, SFX.SMOKE + SFX.FIRE)
     Explode (barrel1b, SFX.SMOKE + SFX.FIRE)
    Explode (turret2, SFX.SMOKE + SFX.FIRE)
     Explode (barrel2, SFX.SMOKE + SFX.FIRE)
    Explode (turret3, SFX.SMOKE + SFX.FIRE)
    Explode (turret4, SFX.SMOKE + SFX.FIRE) 
	  return 2
  else
    Explode (body, SFX.SHATTER)
    Explode (mainrotor, SFX.SMOKE + SFX.FIRE + SFX.EXPLODE)
    Explode (tailrotor, SFX.SMOKE + SFX.FIRE + SFX.EXPLODE)
    Explode (turret1, SFX.SMOKE + SFX.FIRE + SFX.EXPLODE)
     Explode (barrel1a, SFX.SMOKE + SFX.FIRE + SFX.EXPLODE)
     Explode (barrel1b, SFX.SMOKE + SFX.FIRE + SFX.EXPLODE)
    Explode (turret2, SFX.SMOKE + SFX.FIRE + SFX.EXPLODE)
     Explode (barrel2, SFX.SMOKE + SFX.FIRE + SFX.EXPLODE)
    Explode (turret3, SFX.SMOKE + SFX.FIRE + SFX.EXPLODE)
    Explode (turret4, SFX.SMOKE + SFX.FIRE + SFX.EXPLODE) 
	  return 3
  end
end